<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document Title</title>
    <style>
        #app{
            width: 450px;
            border-top: 1px solid #f5f5f5;
        }
        .active{
            background: url("http://img.simoniu.com/check.png") no-repeat right center;
            background-size: 30px 30px;
        }
        #paybox{
            width: 100%;
            background-color: white;
            padding:0 10px;
            margin-bottom: 20px;

        }
        .paylist{
            width: 150px;
        }
        #paybox img{
            width: 28px;
            margin-left: 20px;
        }
    </style>
</head>

<body>
<h1>样式绑定综合实例</h1>
<hr>

<div id="app">
    <div>
        <div>支付方式</div>
        <div id="paybox">
            <div class="paylist"  v-for="(pay,index) in payList" :key="index" :class="{active:pay.active}"
                 @click="selectPay(index)"><span>{{pay.name}}</span><img :src="''+pay.logo" alt=""/></div>

        </div>
    </div>
</div>
<!--使用CDN方式引入vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.4/vue.min.js"></script>


<script>
    let vm = new Vue({
        el: '#app',
        data: {
            payList: [
                {
                    "name": "支付宝",
                    "logo": "http://img.simoniu.com/alipay.jpg",
                    "active": true
                },
                {
                    "name": "微信",
                    "logo": "http://img.simoniu.com/weixin.jpg",
                    "active": false
                },
                {
                    "name": "银联",
                    "logo": "http://img.simoniu.com/unipay.jpg",
                    "active": false
                }
            ]
        },
        methods: {
            selectPay: function (index) {
                for (let i = 0; i < this.payList.length; i++) {
                    this.payList[i].active = false;
                }
                this.payList[index].active = true;
            }
        }
    })
</script>
</body>
</html>

